﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace iPdf
{
    class EmailAddressValidator: IValidator
    {
        public bool IsValidString(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return false;
            }

            ///  Any character in this class: [A-Z0-9._%+-], one or more repetitions
            ///  @
            ///  Any character in this class: [A-Z0-9.-], one or more repetitions
            ///  Literal .
            ///  Any character in this class: [A-Z], between 2 and 4 repetitions
            ///  First or last character in a word
            Regex emailAddrValidator = new Regex(
              "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b",
            RegexOptions.IgnoreCase
            | RegexOptions.CultureInvariant
            | RegexOptions.IgnorePatternWhitespace
            | RegexOptions.Compiled
            );

            return emailAddrValidator.IsMatch(value);
        }
    }
}
